#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void help(){
string s; cin >> s;
map<char,vector<ll>>mp;
for(int i = 0; i < s.size() ; i++){
mp[s[i]].push_back(i);
}
// for(auto it : mp){
// cout << it.first << " -> ";
// for(auto it1 : it.second){
// cout << it1 << " ";
// }
// cout << endl;
// }
ll ans = 0;
for(auto it1 : mp){
vector<ll>temp1 = it1.second;
for(auto it2 : mp){
vector<ll>temp2 = it2.second;
ll n_ = temp2.size();
ll count = 0;
if(it1.first == it2.first){
count = max(n_,(n_*(n_-1))/2);
ans = max(ans,count);
continue;
}
for(int i = 0; i < temp1.size() ; i++){
ll idx = lower_bound(temp2.begin(),temp2.end(),temp1[i])-temp2.begin();
count += n_-idx;
}
ans = max(ans,count);
}
}
cout << ans << endl;
}
int main() {
ll t = 1;
while(t--){
help();
}
}
168B - Wizards and Minimal Spell | 7A - Kalevitch and Chess |
912B - New Year's Eve | 1537C - Challenging Cliffs |
879B - Table Tennis | 1674E - Breaking the Wall |
1282A - Temporarily unavailable | 1366C - Palindromic Paths |
336A - Vasily the Bear and Triangle | 926A - 2-3-numbers |
276D - Little Girl and Maximum XOR | 1253C - Sweets Eating |
1047A - Little C Loves 3 I | 758D - Ability To Convert |
733A - Grasshopper And the String | 216A - Tiling with Hexagons |
1351B - Square | 1225A - Forgetting Things |
1717A - Madoka and Strange Thoughts | 1717B - Madoka and Underground Competitions |
61B - Hard Work | 959B - Mahmoud and Ehab and the message |
802G - Fake News (easy) | 1717C - Madoka and Formal Statement |
420A - Start Up | 1031A - Golden Plate |
1559C - Mocha and Hiking | 427B - Prison Transfer |
330A - Cakeminator | 426A - Sereja and Mugs |